<?php
class NhanviensController extends AppController {

	var $name = 'nhanviens';
	var $helpers = array("Html","Session");
    var $components = array("Common","Session");
    
    function beforeFilter(){
        parent::beforeFilter();
    }
	
	function index() {
		$this->Nhanvien->recursive = 0;
		$this->set('nhanviens', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid nhanvien', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('nhanvien', $this->Nhanvien->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Nhanvien->create();
			if ($this->Nhanvien->save($this->data)) {
				$this->Session->setFlash(__('The nhanvien has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The nhanvien could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid nhanvien', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Nhanvien->save($this->data)) {
				$this->Session->setFlash(__('The nhanvien has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The nhanvien could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Nhanvien->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for nhanvien', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Nhanvien->delete($id)) {
			$this->Session->setFlash(__('Nhanvien deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Nhanvien was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	
	/**
     * Trang chu nhan vien
     */ 
   
	/**
     * Trang chu admin
     */ 
    function admin_index(){
        
       $data = $this->Nhanvien->find("all"); 
       $this->set("data",$data);
    }
    
    /**
     * Cap nhat Nhanvien
     */ 
    
    function admin_edit($id){
        if (!$id && empty($this->data)) {
            $this->Session->setFlash('Invalid Nhanvien');
            $this->redirect("/admin/nhanviens");
        }
        
        if (empty($this->data)) {
                //$level = array("1"=>"administrator","2"=>"Assistant");
                //$this->set("level",$level);
                $this->data = $this->Nhanvien->read(null, $id);
        }else{
            $this->Nhanvien->set($this->data);
            if($this->Nhanvien->validateNhanvien()){
                $this->Nhanvien->save($this->data);
                $this->Session->setFlash("You has been updated Nhanvien with id =".$id);
                $this->redirect("/admin/nhanviens"); 
            }
        }
    }
    
    /**
     * Them moi Nhanvien
     */ 
    function admin_add() {
        if(!empty($this->data)){
          
          $this->Nhanvien->set($this->data);
          if($this->Nhanvien->validateNhanvien()){
            $this->Nhanvien->save($this->data);
            $this->Session->setFlash("You has been add new Nhanvien !");
            $this->redirect("/admin/Nhanviens");  
          }  
          
        }else{
          $this->render();
          
        }
    }
    
    /**
     * Xoa Nhanvien
     */
    function admin_delete($Nhanvien_id){
        if(isset($Nhanvien_id) && is_numeric($Nhanvien_id)){
            $data = $this->Nhanvien->read(null,$id);
            if(!empty($data)){
                $this->Nhanvien->delete($Nhanvien_id);
                $this->Session->setFlash("Nhanvienname has been deleted with id=".$Nhanvien_id);
            }else{
                $this->Session->setFlash("Nhanvienname is not avalible with id=".$Nhanvien_id);
            }
        }else{

            $this->Session->setFlash("Nhanvienname is not avalible with id=".$Nhanvien_id);
        }
        $this->redirect("/admin/nhanviens");
    }
    
    /**
     * Dang nhap
     */    
    function login(){
        
    }
    
    /**
     * Dang xuat
     */ 
    function logout(){
       
    }
}